﻿using ACC.Data.Entities.Client;
using ACC.Data.Entities.Common;
using ACC.Extensions.Entities;
using ACC.Extensions.Utilities;
using ACC.Util.Convert;
using PLCTools.Driver;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace ACC.Extensions.ClientBusiness.PLC
{
    /// <summary>
    /// 西门子PLC
    /// </summary>
    public class SiemensPlcProcess
    {
        protected PLCDriver Driver = null;
        private Thread _monitorThread;
        // add by huangqijun 2018-08-06 start
        private Thread _readPLCDataThread;
        // add by huangqijun 2018-08-06 end

        private object _lockObj = new object();
        private string _IP;
        private string _Param;

        private bool isConnected;
        public bool IsConnected
        {
            get { return isConnected; }
        }
        public bool IsRetryConnect { get; set; }
        public string PlcName { get; set; }
        public LocalSetting PcSetting { get; set; }
        // add by huangqijun 2018-08-06 start
        public ClientConfig CurrentClient { get; set; }
        public ClientPartType CurrentPartType { get; set; }
        public Int32 Shift { get; set; }
        // add by huangqijun 2018-08-06 end

        /// Print用于输出信息
        public delegate void PrintEventHandler(string strData, string strMsg, bool isWaring);
        private PrintEventHandler _OnPrint;

        public delegate void PLCEventHandler(int eventType, bool value);
        public event PLCEventHandler OnPlcTrigger;

        public delegate void ConnectedHandler(string strDeviceName, bool bIsConnected);
        public event ConnectedHandler OnConnected;

        public delegate void PLCConnectedHandler();
        public event PLCConnectedHandler OnPLCConnected;

        public SiemensPlcProcess(PrintEventHandler print = null)
        {
            this._OnPrint = print;
        }
        //_IP = "10.9.48.153"; //_Param = "102;0;0";
        //type = 0 virtual siemens, type=1 siemens plc
        public void InitPLC(int type, string ip, string port, string rack, string slot)
        {
            if (type == 0)
            {
                Driver = (PLCDriver)Activator.CreateInstance(Assembly.LoadFile(Application.StartupPath + "\\PLCTools.Driver.Siemens.dll").GetType("PLCTools.Driver.SieDriver"));
                _IP = ip;
                _Param = port + ";" + (string.IsNullOrEmpty(rack) ? "0" : rack) + ";" + (string.IsNullOrEmpty(slot) ? "0" : slot);
            }
            else
            {
                //Driver = (PLCDriver)Activator.CreateInstance(Assembly.LoadFile(Application.StartupPath + "\\PLCTools.Driver.VSiemens.dll").GetType("PLCTools.Driver.VSiemens.TestSiemensDriver"));
                Driver = (PLCDriver)Activator.CreateInstance(Assembly.LoadFile(Application.StartupPath + "\\PLCTools.Driver.Siemens.dll").GetType("PLCTools.Driver.TestSiemensDriver"));
                _IP = ip;
                _Param = port;
            }

            if (_OnPrint != null) _OnPrint("", "PLC," + _IP + " " + _Param, false);
        }

        public virtual void Start()
        {
            if (_monitorThread == null)
            {
                _monitorThread = new Thread(new ThreadStart(MonitorThreadProcess));
                _monitorThread.IsBackground = true;
                _monitorThread.Name = "PLC Monitor Thread";
                _monitorThread.Start();
            }
        }

        public virtual void Stop()
        {
            try
            {
                IsRetryConnect = false;
                isConnected = false;
                if (_monitorThread != null && _monitorThread.ThreadState == ThreadState.Running)
                {
                    _monitorThread.Join(5000);
                    if (_monitorThread.IsAlive)
                        _monitorThread.Abort();
                }
                _monitorThread = null;

                // add by huangqijun 2018-08-06 start
                if (_readPLCDataThread != null && _readPLCDataThread.ThreadState == ThreadState.Running)
                {
                    _readPLCDataThread.Join(5000);
                    if (_readPLCDataThread.IsAlive)
                        _readPLCDataThread.Abort();
                }
                _readPLCDataThread = null;
                // add by huangqijun 2018-08-06 end

                if (Driver != null)
                {
                    Driver.Disconnect();
                    isConnected = Driver.IsConnected;
                }
                if (OnConnected != null) OnConnected(PlcName, IsConnected);
            }
            catch (Exception ex)
            {
                _monitorThread = null;
                // add by huangqijun 2018-08-06 start
                _readPLCDataThread = null;
                // add by huangqijun 2018-08-06 end
                if (_OnPrint != null) _OnPrint("", "PLC," + ex.Message, true);
                if (OnConnected != null) OnConnected(PlcName, false);
                PLCDBMonitorDisConnected();
            }
        }

        private void MonitorThreadProcess()
        {

            while (true)
            {
                try
                {
                    if (Driver == null)
                    {
                        if (_OnPrint != null) _OnPrint("", "PLC,Driver is NULL", true);
                        if (OnConnected != null) OnConnected(PlcName, false);
                        PLCDBMonitorDisConnected();
                        break;
                    }

                    isConnected = Driver.IsConnected;
                    while (IsRetryConnect && IsConnected == false)
                    {
                        lock (_lockObj)
                        {
                            try
                            {
                                Driver.Connect(_IP, _Param);
                            }
                            catch (Exception ex)
                            {
                                if (_OnPrint != null) _OnPrint("", "PLC," + ex.Message, true);
                            }
                            isConnected = Driver.IsConnected;
                            if (OnConnected != null) OnConnected(PlcName, IsConnected);
                            Thread.Sleep(2000);
                        }
                    }

                    if (IsConnected)
                    {
                        Thread.Sleep(100);
                        try
                        {
                            MonitorPLCRequest();
                        }
                        catch (Exception ex)
                        {
                            Log4Helper.Error("Error：" + ex.Message.ToString());
                            if (_OnPrint != null) _OnPrint("", ex.Message, true);
                        }
                        isConnected = Driver.IsConnected;
                        if (OnConnected != null) OnConnected(PlcName, IsConnected);
                        if (OnPLCConnected != null) OnPLCConnected();

                       
                    }
                }
                catch (Exception ex)
                {
                    Thread.Sleep(100);
                    Log4Helper.Error(ex.StackTrace);
                }
            }
            
        }

        // add by huangqijun 2018-08-06 start
        private void ReadPLCDataThreadProcess()
        {
            while (true)
            {
                if (IsConnected)
                {

                    try
                    {
                        //ReadPLCRealTimeData();
                        //PlcTrigger(9);
                    }
                    catch (Exception ex)
                    {
                        Log4Helper.Error("Error：" + ex.Message.ToString());
                        if (_OnPrint != null) _OnPrint("", ex.Message, true);
                    }
                    Thread.Sleep(10000);
                }
            }
        }
        // add by huangqijun 2018-08-06 end

        //private bool _bCastingDataRequest = false;
        //private bool _bBeginPrintRequest = false;
        //private bool _bPrintRequest = false;
        //private bool _bReadRequest = false;
        private bool _bLoadRequest = false;                 // Load
        protected bool _bUnloadRequest = false;               // UnLoad
        private bool _bPrintRequest = false;                // Print
        private bool _bMaterialInRequest1 = false;          // 上料信号1
        private bool _bMaterialOutRequest1 = false;         // 下料信号1
        private bool _bMaterialInRequest2 = false;          // 上料信号2
        private bool _bMaterialOutRequest2 = false;         // 下料信号2
        private bool _bMaterialInRequest3 = false;          // 上料信号3
        private bool _bMaterialOutRequest3 = false;         // 下料信号3
        private bool _bMaterialInRequest4 = false;          // 上料信号4
        private bool _bMaterialOutRequest4 = false;         // 下料信号4

        private bool _bMaterialCoreInRequest = false;       // 电芯叫料

        bool[] bArray = new bool[16];

        public virtual void MonitorPLCRequest()
        {
            bool bValue = FaultRequest();

            if (bValue && bArray[1] != bValue)
            {
                //LoadResponseReset(); //复位
                PlcTrigger(1);    //Load请求
            }

            bValue = TipRequest();

            if (bValue && bArray[2] != bValue)
            {
                //LoadResponseReset(); //复位
                PlcTrigger(2);    //Load请求
            }

            bool isChanged = PalletRequest(out bValue);
            if (isChanged)
            {
              
                PlcTrigger(3, bValue);    //Pallet请求
            }
            bArray[3] = bValue;

             bValue = LoadRequest();
            if (bValue && bArray[4] != bValue)
            {
                //LoadResponseReset(); //复位
                PlcTrigger(4);    //Load请求
            }
            bArray[4] = bValue;

            isChanged = UnloadRequest();
            if (isChanged)
            {
                PlcTrigger(5);    //UnLoad请求
            }
            bArray[5] = bValue;

            bValue = PrintRequest();
            if (bValue && bArray[15] != bValue)
            {
                PlcTrigger(15);    //Print请求
            }
            bArray[15] = bValue;

            //if (UISession.ClientSetting.UseMaterialInOut)
            {
                bValue = MaterialInRequest1();
                if (bValue && bArray[6] != bValue)
                {
                    PlcTrigger(6);    //上料1请求
                }
                bArray[6] = bValue;

                bValue = MaterialOutRequest1();
                if (bValue && bArray[7] != bValue)
                {
                    PlcTrigger(7);    //下料1请求
                }
                bArray[7] = bValue;

                bValue = MaterialInRequest2();
                if (bValue && bArray[8] != bValue)
                {
                    PlcTrigger(8);    //上料2请求
                }
                bArray[8] = bValue;

                bValue = MaterialOutRequest2();
                if (bValue && bArray[9] != bValue)
                {
                    PlcTrigger(9);    //下料2请求
                }
                bArray[9] = bValue;

                bValue = MaterialInRequest3();
                if (bValue && bArray[10] != bValue)
                {
                    PlcTrigger(10);    //上料3请求
                }
                bArray[10] = bValue;

                bValue = MaterialOutRequest3();
                if (bValue && bArray[11] != bValue)
                {
                    PlcTrigger(11);    //下料3请求
                }
                bArray[11] = bValue;

                bValue = MaterialInRequest4();
                if (bValue && bArray[12] != bValue)
                {
                    PlcTrigger(12);    //上料4请求
                }
                bArray[12] = bValue;

                bValue = MaterialOutRequest4();
                if (bValue && bArray[13] != bValue)
                {
                    PlcTrigger(13);    //下料4请求
                }
                bArray[13] = bValue;

                bValue = MaterialCoreInRequest();
                if (bValue && bArray[14] != bValue)
                {
                    PlcTrigger(14);    //下料4请求
                }
                bArray[14] = bValue;
            }

            for (int i = 1; i < 8; i++)
            {
                string strPlcDbName = "EnablePLCDB" + i.ToString();
                string strPlcDbAddress = "PLCDBAddress" + i.ToString();
                string strPlcDbDescription = "PLCDBDescription" + i.ToString();
                Type type = PcSetting.GetType();
                System.Reflection.PropertyInfo pi = type.GetProperty(strPlcDbName); //获取指定名称的属性
                bool bRes = (bool)pi.GetValue(PcSetting, null); //获取属性值
                pi = type.GetProperty(strPlcDbAddress); //获取指定名称的属性
                string address = pi.GetValue(PcSetting, null).ToString(); //获取属性值
                pi = type.GetProperty(strPlcDbDescription); //获取指定名称的属性
                string description = pi.GetValue(PcSetting, null).ToString(); //获取属性值

                if (bRes)
                {
                    PLCDBMonitor(address, description);
                }
            }
        }

        protected virtual bool TipRequest()
        {
            return false;
        }

        protected virtual bool FaultRequest()
        {
            return false;
        }

        protected  virtual bool PalletRequest(out bool bValue)
        {
            bValue = false;
            return false;
        }

        private void PLCDBMonitor(string strDbAddress, string strDbDescription)
        {
            string[] strArray = strDbAddress.Split('.');
            if (strArray.Length > 2)
            {
                int DBNumber = int.Parse(strArray[0]);
                int position = int.Parse(strArray[1]);
                int bitSite = int.Parse(strArray[2]);
                bool bRes = ReadBit(DBNumber, position, bitSite);
                if (OnConnected != null) OnConnected(strDbDescription, bRes);
            }
        }

        private void PLCDBMonitorDisConnected()
        {
            for (int i = 1; i < 8; i++)
            {
                string strPlcDbName = "EnablePLCDB" + i.ToString();
                string strPlcDbAddress = "PLCDBAddress" + i.ToString();
                string strPlcDbDescription = "PLCDBDescription" + i.ToString();
                Type type = PcSetting.GetType();
                System.Reflection.PropertyInfo pi = type.GetProperty(strPlcDbName); //获取指定名称的属性
                bool bRes = (bool)pi.GetValue(PcSetting, null); //获取属性值
                pi = type.GetProperty(strPlcDbAddress); //获取指定名称的属性
                string address = pi.GetValue(PcSetting, null).ToString(); //获取属性值
                pi = type.GetProperty(strPlcDbDescription); //获取指定名称的属性
                string description = pi.GetValue(PcSetting, null).ToString(); //获取属性值

                if (bRes)
                {
                    if (OnConnected != null) OnConnected(description, false);
                }
            }
        }

        public virtual void PlcTrigger(int eventType)
        {
            PlcTrigger(eventType, true);
        }


        public virtual void PlcTrigger(int eventType, bool value)
        {
            if (null != OnPlcTrigger)
            {
                new Thread(new ThreadStart(delegate()
                {
                    try
                    {
                        OnPlcTrigger(eventType, value);
                    }
                    catch (Exception ex)
                    {
                        Log4Helper.Debug("OnPlcTrigger exception:" + ex.Message + "\r\n" + ex.StackTrace);
                    }
                })).Start();
            }
        }


        //PrintCheck.PLC.Area|182.54|INT  
        //public int PrintArea()
        //{
        //    int DBNumber = 182;
        //    int position = 54;
        //    byte[] buf = new byte[2];
        //    bool bRes = Driver.ReadBytesPLCDB(DBNumber, position, buf);
        //    Array.Reverse(buf);
        //    Log4Helper.Trace("PrintCheck.PLC.Area|182.54|INT  " + BitConverter.ToInt16(buf, 0));
        //    return BitConverter.ToInt16(buf, 0);
        //}


        // Load.Request|180.0.3|BOOL  
        //监控Load请求地址位，有变化时返回true;
        public bool LoadRequest()
        {
            int DBNumber = 0;
            int position = 0;
            int bitSite = 0;

            if (UISession.ClientSetting.EnablePLCDB1)
            {
                ResolvePlcAddress(UISession.ClientSetting.PLCDBAddress1, out DBNumber, out position);
                position += 1;
            }

            byte[] buf = new byte[1];
            Driver.ReadBytesPLCDB(DBNumber, position, buf);
            BitArray arr = new BitArray(buf);

            if (_bLoadRequest != arr[bitSite])
            {
                Log4Helper.Trace(string.Format("Load.Request|{0}.{1}.{2}|BOOL    ", DBNumber, position, bitSite) + arr[bitSite].ToString());
                if (_bLoadRequest == false)
                {
                    _bLoadRequest = arr[bitSite];
                    return true;
                }
                else
                {
                    _bLoadRequest = arr[bitSite];
                    return false;
                }
            }
            else
            {
                return false;
            }
        }

        //ACC.Load.Response.OK|180.3.0|BOOL  
        public virtual void LoadSuccessfully()
        {
            //int DBNumber = 800;
            //int position = 3;
            //int bitSite = 0;
            //bool bValue = true;
            //WriteBit(DBNumber, position, bitSite, bValue);

            //复位PLC Load请求位
            //WriteBit(800, 201, 0, false);

            int DBNumber = 0;
            int position = 0;
            int bitSite = 6;
            if (UISession.ClientSetting.EnablePLCDB1)
            {
                ResolvePlcAddress(UISession.ClientSetting.PLCDBAddress1, out DBNumber, out position);
            }
            // 置位PartOK
            WriteBit(DBNumber, position, 1, true);
            WriteBit(DBNumber, position, 2, false);

            WriteBit(DBNumber, position, bitSite + 1, false);
            WriteBit(DBNumber, position, bitSite, true);

            // 复位PLC Load请求位
            WriteBit(DBNumber, position + 1, 0, false);
        }

        public void SetPartOKNG(bool isOK)
        {
            int DBNumber = 0;
            int position = 0;
            int bitSite = 1;
            if (UISession.ClientSetting.EnablePLCDB1)
            {
                ResolvePlcAddress(UISession.ClientSetting.PLCDBAddress1, out DBNumber, out position);
            }
            // 置位PartOK, PartNG
            WriteBit(DBNumber, position, bitSite, isOK ? true : false);
            WriteBit(DBNumber, position, bitSite + 1, isOK ? false : true);
        }

        //ACC.Load.Response.NOK|180.3.1|BOOL 
        public virtual void LoadFailed()
        {
            int DBNumber = 0;
            int position = 0;
            int bitSite = 7;
            //WriteBit(DBNumber, position, bitSite, bValue);
            if (UISession.ClientSetting.EnablePLCDB1)
            {
                ResolvePlcAddress(UISession.ClientSetting.PLCDBAddress1, out DBNumber, out position);
            }
            WriteBit(DBNumber, position, bitSite - 1, false);
            WriteBit(DBNumber, position, bitSite, true);
        }

        public virtual void WriteParttypeID(Int32 parttypeid)
        {
            int DBNumber = 0;
            int position = 0;
            if (UISession.ClientSetting.EnablePLCDB1)
            {
                ResolvePlcAddress(UISession.ClientSetting.PLCDBAddress1, out DBNumber, out position);
                position += 66;
            }
            byte[] data = ObjectToBytes(ACCPLCUint16Convert((UInt16)parttypeid));
            WriteBytes(DBNumber, position, data);
        }

        public static UInt16 ACCPLCUint16Convert(UInt16 v)
        {
            return (UInt16)(((v & 0xFF) << 8) | ((v & 0xFF00) >> 8));
        }

        public UInt32 ACCPLCUint32Convert(UInt32 v)
        {
            byte a = (byte)(v & 0xff);
            byte b = (byte)((v & 0xff00) >> 8);
            byte c = (byte)((v & 0xff0000) >> 16);
            byte d = (byte)((v & 0xff000000) >> 24);
            return (UInt32)((a << 24) | (b << 16) | (c << 8) | d);
            //return (UInt32)(((v & 0xFF) << 24) | ((v & 0xFF00) << 16) | ((v & 0xff0000) >> 8) | ((v & 0xff000000) >> 24));
        }

        public byte[] ObjectToBytes(object o)
        {
            int size = Marshal.SizeOf(o);
            IntPtr buffer = Marshal.AllocHGlobal(size);
            try
            {
                Marshal.StructureToPtr(o, buffer, false);
                byte[] bytes = new byte[size];
                Marshal.Copy(buffer, bytes, 0, size);
                return bytes;
            }
            finally
            {
                Marshal.FreeHGlobal(buffer);
            }
        }


        //Unload.Request|800.0.4|BOOL 
        public virtual bool UnloadRequest()
        {
            int DBNumber = 0;
            int position = 0;
            int bitSite = 1;
            byte[] buf = new byte[1];
            if (UISession.ClientSetting.EnablePLCDB1)
            {
                ResolvePlcAddress(UISession.ClientSetting.PLCDBAddress1, out DBNumber, out position);
                position += 1;
            }
            Driver.ReadBytesPLCDB(DBNumber, position, buf);
            BitArray arr = new BitArray(buf);

            if (_bUnloadRequest != arr[bitSite])
            {
                Log4Helper.Trace(string.Format("Unload.Request|{0}.{1}.{2}|BOOL   ", DBNumber, position, bitSite) + arr[bitSite].ToString());
                if (_bUnloadRequest == false)
                {
                    _bUnloadRequest = arr[bitSite];
                    return true;
                }
                else
                {
                    _bUnloadRequest = arr[bitSite];
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
        //ACC.Unload.Response.OK|180.4.0|BOOL  
        public virtual void UnloadSuccessfully(int result)
        {
            //int DBNumber = 800;
            //int position = 4;
            //int bitSite = 0;
            //bool bValue = true;
            //WriteBit(DBNumber, position, bitSite, bValue);

            int DBNumber = 0;
            int position = 0;
            int bitSite = 7;
            if (UISession.ClientSetting.EnablePLCDB1)
            {
                ResolvePlcAddress(UISession.ClientSetting.PLCDBAddress1, out DBNumber, out position);
            }

            //复位在线返修位
            if (result > 1)
            {
                WriteBit(DBNumber, position, 3, false);
            }
            else//
            {
                if (result == 1)//OK写位
                {
                    WriteBit(DBNumber, position + 1, bitSite, false);
                    WriteBit(DBNumber, position + 1, bitSite - 1, true);
                }
                else//NG写位
                {
                    WriteBit(DBNumber, position + 1, bitSite - 1, false);
                    WriteBit(DBNumber, position + 1, bitSite, true);
                }
            }

            //复位PLC unLoad请求位
            WriteBit(DBNumber, position + 1, 1, false);
        }

        //ACC.Unload.Response.NOK|180.4.1|BOOL
        public virtual void UnloadFailed()
        {
            int DBNumber = 0;
            int position = 0;
            int bitSite = 7;
            bool bValue = true;
            if (UISession.ClientSetting.EnablePLCDB1)
            {
                ResolvePlcAddress(UISession.ClientSetting.PLCDBAddress1, out DBNumber, out position);
                position += 1;
            }
            WriteBit(DBNumber, position + 1, bitSite, bValue);
        }

        //Print.Request|800.0.5|BOOL 
        public bool PrintRequest()
        {
            int DBNumber = 0;
            int position = 0;
            int bitSite = 5;
            byte[] buf = new byte[1];
            if (UISession.ClientSetting.EnablePLCDB1)
            {
                ResolvePlcAddress(UISession.ClientSetting.PLCDBAddress1, out DBNumber, out position);
            }
            Driver.ReadBytesPLCDB(DBNumber, position, buf);
            BitArray arr = new BitArray(buf);

            if (_bPrintRequest != arr[bitSite])
            {
//                Log4Helper.Trace(string.Format("Print.Request|{0}.{1}.{2}|BOOL   ", DBNumber, position, bitSite) + arr[bitSite].ToString());
                if (_bPrintRequest == false)
                {
                    _bPrintRequest = arr[bitSite];
                    return true;
                }
                else
                {
                    _bPrintRequest = arr[bitSite];
                    return false;
                }
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 上料信号1
        /// </summary>
        /// <returns></returns>
        public bool MaterialInRequest1()
        {
            int DBNumber = 0;
            int position = 0;
            int bitSite = 0;
            byte[] buf = new byte[1];
            if (UISession.ClientSetting.EnablePLCDB1)
            {
                ResolvePlcAddress(UISession.ClientSetting.PLCDBAddress1, out DBNumber, out position);
                position += 68;
            }
            Driver.ReadBytesPLCDB(DBNumber, position, buf);
            BitArray arr = new BitArray(buf);

            if (_bMaterialInRequest1 != arr[bitSite])
            {
                Log4Helper.Trace(string.Format("MaterialIn.Request|{0}.{1}.{2}|BOOL   ", DBNumber, position, bitSite) + arr[bitSite].ToString());
                if (_bMaterialInRequest1 == false)
                {
                    _bMaterialInRequest1 = arr[bitSite];
                    return true;
                }
                else
                {
                    _bMaterialInRequest1 = arr[bitSite];
                    return false;
                }
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 上料信号2
        /// </summary>
        /// <returns></returns>
        public bool MaterialInRequest2()
        {
            int DBNumber = 0;
            int position = 0;
            int bitSite = 2;
            byte[] buf = new byte[1];
            if (UISession.ClientSetting.EnablePLCDB1)
            {
                ResolvePlcAddress(UISession.ClientSetting.PLCDBAddress1, out DBNumber, out position);
                position += 68;
            }
            Driver.ReadBytesPLCDB(DBNumber, position, buf);
            BitArray arr = new BitArray(buf);

            if (_bMaterialInRequest2 != arr[bitSite])
            {
                Log4Helper.Trace(string.Format("MaterialIn.Request|{0}.{1}.{2}|BOOL   ", DBNumber, position, bitSite) + arr[bitSite].ToString());
                if (_bMaterialInRequest2 == false)
                {
                    _bMaterialInRequest2 = arr[bitSite];
                    return true;
                }
                else
                {
                    _bMaterialInRequest2 = arr[bitSite];
                    return false;
                }
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 上料信号3
        /// </summary>
        /// <returns></returns>
        public bool MaterialInRequest3()
        {
            int DBNumber = 0;
            int position = 0;
            int bitSite = 4;
            byte[] buf = new byte[1];
            if (UISession.ClientSetting.EnablePLCDB1)
            {
                ResolvePlcAddress(UISession.ClientSetting.PLCDBAddress1, out DBNumber, out position);
                position += 68;
            }
            Driver.ReadBytesPLCDB(DBNumber, position, buf);
            BitArray arr = new BitArray(buf);

            if (_bMaterialInRequest3 != arr[bitSite])
            {
                Log4Helper.Trace(string.Format("MaterialIn.Request|{0}.{1}.{2}|BOOL   ", DBNumber, position, bitSite) + arr[bitSite].ToString());
                if (_bMaterialInRequest3 == false)
                {
                    _bMaterialInRequest3 = arr[bitSite];
                    return true;
                }
                else
                {
                    _bMaterialInRequest3 = arr[bitSite];
                    return false;
                }
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 上料信号4
        /// </summary>
        /// <returns></returns>
        public bool MaterialInRequest4()
        {
            int DBNumber = 0;
            int position = 0;
            int bitSite = 6;
            byte[] buf = new byte[1];
            if (UISession.ClientSetting.EnablePLCDB1)
            {
                ResolvePlcAddress(UISession.ClientSetting.PLCDBAddress1, out DBNumber, out position);
                position += 68;
            }
            Driver.ReadBytesPLCDB(DBNumber, position, buf);
            BitArray arr = new BitArray(buf);

            if (_bMaterialInRequest4 != arr[bitSite])
            {
                Log4Helper.Trace(string.Format("MaterialIn.Request|{0}.{1}.{2}|BOOL   ", DBNumber, position, bitSite) + arr[bitSite].ToString());
                if (_bMaterialInRequest4 == false)
                {
                    _bMaterialInRequest4 = arr[bitSite];
                    return true;
                }
                else
                {
                    _bMaterialInRequest4 = arr[bitSite];
                    return false;
                }
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 下料信号1
        /// </summary>
        /// <returns></returns>
        public bool MaterialOutRequest1()
        {
            int DBNumber = 0;
            int position = 0;
            int bitSite = 1;
            byte[] buf = new byte[1];
            if (UISession.ClientSetting.EnablePLCDB1)
            {
                ResolvePlcAddress(UISession.ClientSetting.PLCDBAddress1, out DBNumber, out position);
                position += 68;
            }
            Driver.ReadBytesPLCDB(DBNumber, position, buf);
            BitArray arr = new BitArray(buf);

            if (_bMaterialOutRequest1 != arr[bitSite])
            {
                Log4Helper.Trace(string.Format("MaterialOut.Request|{0}.{1}.{2}|BOOL   ", DBNumber, position, bitSite) + arr[bitSite].ToString());
                if (_bMaterialOutRequest1 == false)
                {
                    _bMaterialOutRequest1 = arr[bitSite];
                    return true;
                }
                else
                {
                    _bMaterialOutRequest1 = arr[bitSite];
                    return false;
                }
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 下料信号2
        /// </summary>
        /// <returns></returns>
        public bool MaterialOutRequest2()
        {
            int DBNumber = 0;
            int position = 0;
            int bitSite = 3;
            byte[] buf = new byte[1];
            if (UISession.ClientSetting.EnablePLCDB1)
            {
                ResolvePlcAddress(UISession.ClientSetting.PLCDBAddress1, out DBNumber, out position);
                position += 68;
            }
            Driver.ReadBytesPLCDB(DBNumber, position, buf);
            BitArray arr = new BitArray(buf);

            if (_bMaterialOutRequest2 != arr[bitSite])
            {
                Log4Helper.Trace(string.Format("MaterialOut.Request|{0}.{1}.{2}|BOOL   ", DBNumber, position, bitSite) + arr[bitSite].ToString());
                if (_bMaterialOutRequest2 == false)
                {
                    _bMaterialOutRequest2 = arr[bitSite];
                    return true;
                }
                else
                {
                    _bMaterialOutRequest2 = arr[bitSite];
                    return false;
                }
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 下料信号3
        /// </summary>
        /// <returns></returns>
        public bool MaterialOutRequest3()
        {
            int DBNumber = 0;
            int position = 0;
            int bitSite = 5;
            byte[] buf = new byte[1];
            if (UISession.ClientSetting.EnablePLCDB1)
            {
                ResolvePlcAddress(UISession.ClientSetting.PLCDBAddress1, out DBNumber, out position);
                position += 68;
            }
            Driver.ReadBytesPLCDB(DBNumber, position, buf);
            BitArray arr = new BitArray(buf);

            if (_bMaterialOutRequest3 != arr[bitSite])
            {
                Log4Helper.Trace(string.Format("MaterialOut.Request|{0}.{1}.{2}|BOOL   ", DBNumber, position, bitSite) + arr[bitSite].ToString());
                if (_bMaterialOutRequest3 == false)
                {
                    _bMaterialOutRequest3 = arr[bitSite];
                    return true;
                }
                else
                {
                    _bMaterialOutRequest3 = arr[bitSite];
                    return false;
                }
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 下料信号4
        /// </summary>
        /// <returns></returns>
        public bool MaterialOutRequest4()
        {
            int DBNumber = 0;
            int position = 0;
            int bitSite = 7;
            byte[] buf = new byte[1];
            if (UISession.ClientSetting.EnablePLCDB1)
            {
                ResolvePlcAddress(UISession.ClientSetting.PLCDBAddress1, out DBNumber, out position);
                position += 68;
            }
            Driver.ReadBytesPLCDB(DBNumber, position, buf);
            BitArray arr = new BitArray(buf);

            if (_bMaterialOutRequest4 != arr[bitSite])
            {
                Log4Helper.Trace(string.Format("MaterialOut.Request|{0}.{1}.{2}|BOOL   ", DBNumber, position, bitSite) + arr[bitSite].ToString());
                if (_bMaterialOutRequest4 == false)
                {
                    _bMaterialOutRequest4 = arr[bitSite];
                    return true;
                }
                else
                {
                    _bMaterialOutRequest4 = arr[bitSite];
                    return false;
                }
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 三大件叫料信号
        /// </summary>
        /// <returns></returns>
        public bool MaterialCoreInRequest()
        {
            int DBNumber = 0;
            int position = 0;
            int bitSite = 0;
            byte[] buf = new byte[1];
            if (UISession.ClientSetting.EnablePLCDB1)
            {
                ResolvePlcAddress(UISession.ClientSetting.PLCDBAddress1, out DBNumber, out position);
                position += 69;
            }
            Driver.ReadBytesPLCDB(DBNumber, position, buf);
            BitArray arr = new BitArray(buf);

            if (_bMaterialCoreInRequest != arr[bitSite])
            {
                Log4Helper.Trace(string.Format("MaterialOut.Request|{0}.{1}.{2}|BOOL   ", DBNumber, position, bitSite) + arr[bitSite].ToString());
                if (_bMaterialCoreInRequest == false)
                {
                    _bMaterialCoreInRequest = arr[bitSite];
                    return true;
                }
                else
                {
                    _bMaterialCoreInRequest = arr[bitSite];
                    return false;
                }
            }
            else
            {
                return false;
            }
        }

        public void MaterialInResult(int bitSite)
        {
            int DBNumber = 0;
            int position = 0;
            if (UISession.ClientSetting.EnablePLCDB1)
            {
                ResolvePlcAddress(UISession.ClientSetting.PLCDBAddress1, out DBNumber, out position);
                position += 68;
            }
            WriteBit(DBNumber, position, bitSite, false);

        }

        public void MaterialOutResult(int bitSite)
        {
            int DBNumber = 0;
            int position = 0;
            if (UISession.ClientSetting.EnablePLCDB1)
            {
                ResolvePlcAddress(UISession.ClientSetting.PLCDBAddress1, out DBNumber, out position);
                position += 68;
            }
            WriteBit(DBNumber, position, bitSite, false);

        }

        public void MaterialCoreInResult(int bitSite)
        {
            int DBNumber = 0;
            int position = 0;
            if (UISession.ClientSetting.EnablePLCDB1)
            {
                ResolvePlcAddress(UISession.ClientSetting.PLCDBAddress1, out DBNumber, out position);
                position += 69;
            }
            WriteBit(DBNumber, position, bitSite, false);

        }


        public int GetGetOKCount()
        {
            int DBNumber = 0;
            int position = 0;
            if (UISession.ClientSetting.EnablePLCDB1)
            {
                ResolvePlcAddress(UISession.ClientSetting.PLCDBAddress1, out DBNumber, out position);
                position += 104;
            }

            int okCount = 0;
            byte[] buf = new byte[2];
            bool bRes = Driver.ReadBytesPLCDB(DBNumber, position, buf);
            if (bRes)
            {
                okCount = ConvertBytesToInt(buf);
            }
            Log4Helper.Trace(DBNumber + "." + position + ":" + okCount);
            return okCount;
        }

        public string GetTrayNo()
        {
            int DBNumber = 0;
            int position = 0;
            if (UISession.ClientSetting.EnablePLCDB1)
            {
                ResolvePlcAddress(UISession.ClientSetting.PLCDBAddress1, out DBNumber, out position);
                position += 34;
            }

            byte[] buf = new byte[2];
            bool bRes = Driver.ReadBytesPLCDB(DBNumber, position, buf);
            string trayNo = string.Empty;
            if (bRes)
            {
                int realLen = buf[1];
                if (realLen > 0)
                {
                    buf = new byte[realLen];
                    bRes = Driver.ReadBytesPLCDB(DBNumber, position + 2, buf);
                    trayNo = Encoding.ASCII.GetString(buf);
                    trayNo = trayNo.TrimEnd('\0');
                }
            }
            Log4Helper.Trace(DBNumber + "." + position + ":" + trayNo);
            //byte[] buf = new byte[30];
            //string trayNo = string.Empty;
            //if(Driver.ReadBytesPLCDB(DBNumber, position, buf))
            //    trayNo = Encoding.Default.GetString(buf).Replace("\0", "").Trim();
            //Log4Helper.Trace(DBNumber + "." + position + ":" + trayNo);
            return trayNo;
        }

        /// <summary>
        /// Unlaod时读取托盘号
        /// </summary>
        /// <returns></returns>
        public string GetUnloadTrayNo()
        {
            int DBNumber = 0;
            int position = 0;
            if (UISession.ClientSetting.EnablePLCDB1)
            {
                ResolvePlcAddress(UISession.ClientSetting.PLCDBAddress1, out DBNumber, out position);
                position += 72;
            }

            byte[] buf = new byte[2];
            bool bRes = Driver.ReadBytesPLCDB(DBNumber, position, buf);
            string trayNo = string.Empty;
            if (bRes)
            {
                int realLen = buf[1];
                if (realLen > 0)
                {
                    buf = new byte[realLen];
                    bRes = Driver.ReadBytesPLCDB(DBNumber, position + 2, buf);
                    trayNo = Encoding.ASCII.GetString(buf);
                    trayNo = trayNo.TrimEnd('\0');
                }
            }
            Log4Helper.Trace(DBNumber + "." + position + ":" + trayNo);
            return trayNo;
        }

        /// <summary>
        /// 读取过程数据
        /// </summary>
        /// <param name="lstProcessData"></param>
        public virtual void GetProcData(ref List<ClientProcData> lstProcessData)
        {
            int DBNumber = 800;
            double d_value = 0.0;
            int i_value = 0;
            string str_value = "";
            try
            {
                foreach (ClientProcData procData in lstProcessData)
                {
                    if (procData.ValueType.ToUpper() == "DOUBLE")
                    {
                        byte[] buf = new byte[4];
                        bool bRes = Driver.ReadBytesPLCDB(DBNumber, procData.Position, buf);
                        if (bRes)
                        {
                            Array.Reverse(buf);
                            d_value = Convert.ToDouble(BitConverter.ToSingle(buf, 0).ToString());
                            procData.Value = d_value;
                        }
                        else
                        {
                            Log4Helper.Error("read procdata failed");
                        }
                    }
                    else if (procData.ValueType.ToUpper() == "INT")
                    {
                        byte[] buf = new byte[2];
                        bool bRes = Driver.ReadBytesPLCDB(DBNumber, procData.Position, buf);
                        if (bRes)
                        {
                            Array.Reverse(buf);
                            i_value = BitConverter.ToInt16(buf, 0);
                            procData.Value = i_value;
                        }
                        else
                        {
                            Log4Helper.Error("read procdata failed");
                        }
                    }
                    else if (procData.ValueType.ToUpper() == "STRING")
                    {
                        byte[] buf = new byte[2];
                        bool bRes = Driver.ReadBytesPLCDB(DBNumber, procData.Position, buf);
                        if (bRes)
                        {
                            int realLen = buf[1];
                            if (realLen > 0)
                            {
                                buf = new byte[realLen];
                                bRes = Driver.ReadBytesPLCDB(DBNumber, procData.Position + 2, buf);
                                str_value = Encoding.ASCII.GetString(buf);
                            }
                            else
                            {
                                str_value = string.Empty;
                            }
                            procData.Value = str_value;
                        }
                        else
                        {
                            Log4Helper.Error("read procdata failed");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log4Helper.Error("read procdata failed", ex);
            }
        }

        public string GetFixtureNum()
        {
            int DBNumber = 0;
            int position = 0;
            if (UISession.ClientSetting.EnablePLCDB1)
            {
                ResolvePlcAddress(UISession.ClientSetting.PLCDBAddress1, out DBNumber, out position);
                position += 34;
            }
            byte[] buf = new byte[2];
            bool bRes = Driver.ReadBytesPLCDB(DBNumber, position, buf);
            string fixtureNum = string.Empty;
            if (bRes)
            {
                int realLen = buf[1];
                if (realLen > 0)
                {
                    buf = new byte[realLen];
                    bRes = Driver.ReadBytesPLCDB(DBNumber, position + 2, buf);
                    fixtureNum = Encoding.ASCII.GetString(buf);
                }
            }
            Log4Helper.Trace(DBNumber + "." + position + ":" + fixtureNum);
            return fixtureNum;
        }

        protected void WriteBit(int DBNumber, int position, int bitSite, bool bValue)
        {
            try
            {
                Log4Helper.Trace("WriteBit," + DBNumber + "." + position + "." + bitSite + "." + bValue.ToString());
                int pos = (position * 8 + bitSite);
                Driver.WriteBitPLCDB(DBNumber, pos, bValue);
            }
            catch (Exception ex)
            {
                throw;
            }        
        }

        protected bool WriteBytes(int DBNumber, int position, byte[] buf)
        {
            Log4Helper.Trace("WriteBytes," + DBNumber + "." + position + "." + System.Text.Encoding.Default.GetString(buf));
            int pos = position;
            return Driver.WriteBytesPLCDB(DBNumber, pos, buf);
        }

        private bool ReadBit(int DBNumber, int position, int bitSite)
        {
            byte[] buf = new byte[1];
            Driver.ReadBytesPLCDB(DBNumber, position, buf);
            BitArray arr = new BitArray(buf);
            return arr[bitSite];
        }

        private int ConvertBytesToInt(byte[] buf)
        {
            int value = 0;
            try
            {
                List<byte> lsData = new List<byte>(buf);
                lsData.Reverse();
                if (buf.Length == 2)
                {
                    value = BitConverter.ToInt16(lsData.ToArray(), 0);
                }
                else
                {
                    value = BitConverter.ToInt32(lsData.ToArray(), 0);
                }
            }
            catch (Exception ex)
            {
                Log4Helper.Error(ex);
            }
            return value;
        }

        /// <summary>
        /// 把宇通内部码写入PLC
        /// </summary>
        /// <param name="unitSN"></param>
        public virtual void WriteInterSNToPlc(string unitSN)
        {
            byte[] data = new byte[32];
            data[0] = 30;
            data[1] = (byte)unitSN.Length;
            byte[] temp = Encoding.ASCII.GetBytes(unitSN);
            Array.Copy(temp, 0, data, 2, temp.Length);

            int DBNumber = 800;
            int position = 2;
            if (UISession.ClientSetting.EnablePLCDB1)
            {
                ResolvePlcAddress(UISession.ClientSetting.PLCDBAddress1, out DBNumber, out position);
                position += 2;
            }

            WriteBytes(DBNumber, position, data);
        }

        /// <summary>
        /// 把国标码写入PLC
        /// </summary>
        /// <param name="unitSN"></param>
        public void WriteGBSNToPlc(string unitSN)
        {
            try
            {
                byte[] data = new byte[32];
                data[0] = 30;
                data[1] = (byte)unitSN.Length;
                byte[] temp = Encoding.ASCII.GetBytes(unitSN);
                Array.Copy(temp, 0, data, 2, temp.Length);

                int DBNumber = 0;
                int position = 0;
                if (UISession.ClientSetting.EnablePLCDB1)
                {
                    ResolvePlcAddress(UISession.ClientSetting.PLCDBAddress1, out DBNumber, out position);
                    position += 72;
                }

                WriteBytes(DBNumber, position, data);
            }
            catch (Exception ex)
            {
                Log4Helper.Error(ex.Message + "\r\n" + ex.StackTrace);
            }
        }

        /// <summary>
        /// 把订单号写入PLC
        /// </summary>
        /// <param name="unitSN"></param>
        public void WriteOrderNoToPlc(string orderNo)
        {
            try
            {
                byte[] data = new byte[32];
                data[0] = 30;
                data[1] = (byte)orderNo.Length;
                byte[] temp = Encoding.ASCII.GetBytes(orderNo);
                Array.Copy(temp, 0, data, 2, temp.Length);

                int DBNumber = 0;
                int position = 0;
                if (UISession.ClientSetting.EnablePLCDB1)
                {
                    ResolvePlcAddress(UISession.ClientSetting.PLCDBAddress1, out DBNumber, out position);
                    position += 72;
                }

                WriteBytes(DBNumber, position, data);
            }
            catch (Exception ex)
            {
                Log4Helper.Error(ex.Message + "\r\n" + ex.StackTrace);
            }
        }

        /// <summary>
        /// 把订单数量写入PLC
        /// </summary>
        /// <param name="unitSN"></param>
        public void WritePlanCountToPlc(string planCount)
        {
            try
            {
                int num = 0;
                int.TryParse(planCount, out num);

                int DBNumber = 0;
                int position = 0;
                if (UISession.ClientSetting.EnablePLCDB1)
                {
                    ResolvePlcAddress(UISession.ClientSetting.PLCDBAddress1, out DBNumber, out position);
                    position += 116;
                }

                byte[] data = ObjectToBytes(ACCPLCUint16Convert((UInt16)num));
                //Array.Reverse(data);
                WriteBytes(DBNumber, position, data);
            }
            catch (Exception ex)
            {
                Log4Helper.Error(ex.Message + "\r\n" + ex.StackTrace);
            }
        }

        /// <summary>
        /// 把产品型号写入PLC
        /// </summary>
        /// <param name="unitSN"></param>
        public void WritePartNoToPlc(string partNo)
        {
            try
            {
                byte[] data = new byte[12];
                data[0] = 10;
                data[1] = (byte)partNo.Length;
                byte[] temp = Encoding.ASCII.GetBytes(partNo);
                Array.Copy(temp, 0, data, 2, temp.Length);

                int DBNumber = 0;
                int position = 0;
                if (UISession.ClientSetting.EnablePLCDB1)
                {
                    ResolvePlcAddress(UISession.ClientSetting.PLCDBAddress1, out DBNumber, out position);
                    position += 104;
                }

                WriteBytes(DBNumber, position, data);
            }
            catch (Exception ex)
            {
                Log4Helper.Error(ex.Message + "\r\n" + ex.StackTrace);
            }
        }

        /// <summary>
        /// 从配置项里解析DB块、偏移量
        /// </summary>
        /// <param name="plcAddress"></param>
        protected void ResolvePlcAddress(string plcAddress, out int dbNumber, out int position)
        {
            dbNumber = 0;
            position = 0;
            //bitSite = 0;
            try
            {
                if (string.IsNullOrEmpty(plcAddress))
                {
                    Log4Helper.Info("ResolvePlcAddress:" + "plcAddress is NullOrEmpty");
                    return;
                }
                string[] datas = plcAddress.Split('.');
                if (datas != null && datas.Length > 0)
                    dbNumber = Convert.ToInt32(datas[0]);
                if (datas != null && datas.Length > 1)
                    position = Convert.ToInt32(datas[1]);
            }
            catch (Exception ex)
            {
                Log4Helper.Error("ResolvePlcAddress:" + plcAddress, ex);
            }
        }

        /// <summary>
        /// 从配置项里解析DB块、偏移量
        /// </summary>
        /// <param name="plcAddress"></param>
        protected void ResolvePlcDbNumber(string plcAddress, out int dbNumber)
        {
            dbNumber = 0;
            //bitSite = 0;
            try
            {
                if (string.IsNullOrEmpty(plcAddress))
                {
                    Log4Helper.Info("ResolvePlcAddress:" + "plcAddress is NullOrEmpty");
                    return;
                }
                string[] datas = plcAddress.Split('.');
                if (datas != null && datas.Length > 0)
                    dbNumber = Convert.ToInt32(datas[0]);
            }
            catch (Exception ex)
            {
                Log4Helper.Error("ResolvePlcAddress:" + plcAddress, ex);
            }
        }

        #region PartType Data
        public virtual bool WritePartTypeDataACC(Hashtable htPartTypeDataParam, bool clear)
        {
            try
            {
                int PartTypeDataIntLength = 100;
                int PartTypeDataRealLength = 50;
                int PartTypeDataStringLength = 0;
                int PartTypeDataStringDataLength = 30;
                //int ProcessDataStringDataLength = 30;
                SortedList listInt = (SortedList)htPartTypeDataParam["N_INT"];
                SortedList listReal = (SortedList)htPartTypeDataParam["N_REAL"];
                SortedList listString = (SortedList)htPartTypeDataParam["N_STRING"];
                byte[] data = new byte[2 * PartTypeDataIntLength + 4 * PartTypeDataRealLength + (PartTypeDataStringDataLength + 2) * PartTypeDataStringLength];
                int index = 0;
                byte[] temp;
                int dbNumber = 0;
                int position = 0;
                int position1 = 0;
                if (UISession.ClientSetting.EnablePLCDB2)
                {
                    ResolvePlcAddress(UISession.ClientSetting.PLCDBAddress2, out dbNumber, out position);
                    position1 = position;
                    position += 200;
                }
                //dbNumber = 80;
                // 写入前先清空
                if (clear)
                {
                    if (!WriteBytes(dbNumber, position, data))
                    {
                        return false;
                    }
                }

                for (int i = 1; i <= PartTypeDataIntLength; i++)
                {
                    if (listInt.Contains(i))
                    {
                        temp = BitConverter.GetBytes(Convert.ToInt16(listInt[i]));
                        Array.Reverse(temp);
                        Array.Copy(temp, 0, data, index, temp.Length);
                    }
                    index += 2;
                }
                for (int i = 1; i <= PartTypeDataRealLength; i++)
                {
                    if (listReal.Contains(i))
                    {
                        temp = BitConverter.GetBytes(ByteUtils.ACCPLCFloatConvert(Convert.ToSingle(listReal[i])));
                        Array.Copy(temp, 0, data, index, temp.Length);
                    }
                    index += 4;
                }

                for (int i = 1; i <= PartTypeDataStringLength; i++)
                {
                    if (listString.Contains(i))
                    {
                        data[index] = (byte)PartTypeDataStringDataLength;
                        data[index + 1] = (byte)listString[i].ToString().Length;
                        temp = Encoding.ASCII.GetBytes(listString[i].ToString());
                        Array.Copy(temp, 0, data, index + 2, temp.Length > PartTypeDataStringDataLength ? (int)PartTypeDataStringDataLength : temp.Length);
                    }
                    index += (int)(PartTypeDataStringDataLength + 2);
                }

                if (WriteBytes(dbNumber, position, data))
                {
                    // 写入PLC型号ID
                    //data = BitConverter.GetBytes(UISession.CurrentPartType.PartTypeId);
                    data = ObjectToBytes(ACCPLCUint16Convert((UInt16)UISession.CurrentPartType.PartTypeId));
                    return WriteBytes(80, position1, data);
                }
            }
            catch (Exception ex)
            {
                Log4Helper.Error(ex.StackTrace);
            }

            return false;
        }

        //protected override bool ReadPartTypeDataPLC(out Hashtable htPartTypeDataParam)
        //{
        //    htPartTypeDataParam = new Hashtable();
        //    byte[] buf = new byte[2];
        //    if (!ReadDBBytes(DB190, DB192_PLC_Offset, buf))
        //    {
        //        return false;
        //    }
        //    Array.Reverse(buf);
        //    htPartTypeDataParam.Add("PartTypeID", BitConverter.ToInt16(buf, 0));
        //    return true;
        //}

        //protected override bool WritePartTypeDataComm(ACCCode rs)
        //{
        //    int pos = rs == ACCCode.ACCOK ? ACCIndex_PartData_OK : ACCIndex_PartData_NOK;
        //    if (pos >= 0)
        //        return WriteResultPosToComm(pos, true);

        //    return true;
        //}
        #endregion

        public virtual void WriteBarcodes(List<string> barcodes)
        {
            
        }

        public virtual void GetStatusBits(out int statusBit, out int failureBits)
        {
            statusBit = 0;
            failureBits = 0;
        }

        public virtual void GetFaultMessage(out int code, out string msg)
        {
            code = 0;
            msg = "";
        }

        public virtual void GetTipMessage( out string msg,out bool alarm)
        {
            msg = "";
            alarm = false;
        }

        public virtual void LoadByPass()
        {
            
        }
    }
}
